<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/html/axios.min.js"></script>
    <script>
        function $(id) {
         return document.getElementById(id)
        }
        function getQuery(variable)
        {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++) {
                var pair = vars[i].split("=");
                if(pair[0] == variable){return pair[1];}
            }
            return(false);
        }
        window.onload = function (){
            findByItem(1);
        }
        function findByItem(pageNum) {
            axios.get("/main/findByItem",{
                params:{
                    pageNum:pageNum,
                    name:$("title").value,
                    author:$("author").value,
                    chanelId:getQuery("id"),
                    startDDate:$("startDate").value,
                    endDate:$("endDate").value
                }
            }).then(resp =>{
                var obj = resp.data.list;
                var str = ""
                obj.forEach(e =>{
                    str +=`<tr><td>${e.title}</td><td>${e.author}</td><td>${e.postNumber}</td><td>${e.postDate}</td>
                     <td><a href="addTopic.html?id=${e.channel.id}&name=${e.channel.name}" >发表</a>
                     <a href="post.html?id=${e.id}&name=${e.name}&number=${e.postNumber}" >回帖</a></td</tr>`
                    $("mainDate").innerHTML = str
                });
                let pageN ="";
                for(let i=1;i<=resp.data.pages;i++){
                    pageN +=`<a style="margin-left: 10px" href="javascript:findByItem(${i})">${i}</a>`
                    $("pageDiv").innerHTML =pageN;
                }
            });
        }
        function topic() {
           location.href="/html/addTopic.html"
        }
    </script>
</head>
<body>
     <table border="1" width="60%" cellspacing="0">
          <thead>
              <tr><td>主题</td><td>作者</td><td>回帖数量</td><td>发帖时间</td><td>操作</td></tr>
          </thead>
         <tbody id="mainDate"></tbody>
     </table>
     <div id="pageDiv"></div>
     主题名称:<input type="text" id="title"><br>
     作者：<input type="text" id="author"><br>
     起始日期:<input type="text" id="startDate"><br>
     结束日期:<input type="text" id="endDate"><br>
     <input type="button" value="搜索"> <br>
</body>
</html>